package de.baumann.browser.activitys.oc

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.util.Log
import de.baumann.browser.R
import de.baumann.browser.adapter.MnemonicAdapter
import de.baumann.browser.base.BaseOdinActivity
import de.baumann.browser.base.BasePresenter
import de.baumann.browser.db.ETHWallet
import de.baumann.browser.iview.IBaseView
import de.baumann.browser.utils.web3j.OdinWallet
import kotlinx.android.synthetic.main.activity_oc_mnemonic.*
import kotlinx.android.synthetic.main.include_tool_bar.*

class OcMnemonicActivity : BaseOdinActivity<IBaseView, BasePresenter<IBaseView>>() {

    companion object {
        fun startOcMnemonicActivity(context: Context, ethWallet: ETHWallet) {
            context.startActivity(Intent(context, OcMnemonicActivity::class.java).apply {
                val bundle = Bundle().apply {
                    putSerializable("ethWallet",ethWallet)
                }
                putExtras(bundle)
            })
        }
    }

    private lateinit var mnemonicAdapter: MnemonicAdapter

    override fun getLayout(): Int {
        OdinWallet.addAtivity(this)
        return R.layout.activity_oc_mnemonic
    }

    override fun getTitleText(): String {
        return "备份助记词"
    }

    override fun initView() {
        initToolbar(commToolBar, commTitle)
        btnMnemonic.setOnClickListener {
            OcMnemonicConfirmActivity.startOcMnemonicConfirmActivity(mContext,getEthWallet())
            finish()
        }
        mnemonicAdapter = MnemonicAdapter(mContext, null, null)
        rvMnemonic.adapter = mnemonicAdapter
    }

    private lateinit var mnemonic: String
    override fun initData() {
        mnemonic = getEthWallet().mnemonic
        val mnemonicArr = mnemonic.split(" ")
        mnemonicAdapter.mnemonicArr = mnemonicArr as ArrayList<String>
    }

    override fun createPresenter(): BasePresenter<IBaseView>? {
        return null
    }

    override fun createView(): IBaseView? {
        return null
    }

    private fun getEthWallet():ETHWallet{
        return intent.getSerializableExtra("ethWallet") as ETHWallet
    }

    override fun onDestroy() {
        super.onDestroy()
        OdinWallet.removeActivity(this)
    }

    override fun showBindEth(): Boolean {
        return false
    }
}
